<?php

namespace CtyunOss;

use CtyunOss\api\OssBucket;
use CtyunOss\config\OssConfig;
use CtyunOss\exceptions\OssConfigException;
use CtyunOss\api\OssService;
use Symfony\Component\VarDumper\VarDumper;

/**
 * 天翼云OSS 核心入口
 * @package    CtyunOss
 *
 * @author     Violet_Ice紫冰 <violetice@aliyun.com>
 * @create     2020-06-24 15:32:53
 */
class CtyunOss
{
    /** @var OssConfig 天翼云OSS配置 */
    private $config;

    /**
     * CtyunOss constructor.
     *
     * @param OssConfig $config
     *
     * @throws OssConfigException
     */
    public function __construct(OssConfig $config)
    {
        if (empty($config->getAccessKeyId())) {
            throw new OssConfigException('AccessKeyId 不能为空');
        }
        if (empty($config->getSecretAccessKey())) {
            throw new OssConfigException('SecretAccessKey 不能为空');
        }
        if ($config->debug) {
            VarDumper::dump('开启调试模式');
        }

        $this->config = $config;
    }

    /**
     * 天翼云OSS Service操作
     * @return OssService
     */
    public function service()
    {
        return new OssService($this->config);
    }

    /**
     * 天翼云OSS Bucket操作
     * @return OssBucket
     */
    public function bucket()
    {
        return new OssBucket($this->config);
    }
}